library(knitr) library(oSCR) #library(scrbook) options(width=120) options(width.cutoff=80) opts_chunk$set(prompt = FALSE, comment = NA, mysize=TRUE, size="\\scriptsize") hook1 <- function(x){ gsub("```\n*```r*\n*", "", x) } hook2 <- function(x){ gsub("```\n+```\n", "", x) } knit_hooks$set(document = hook2) knitr::knit_hooks$set(mysize = function(before, options, envir) { if (before) return(options$size) })
The \textcolor{mLightBrown}{\texttt{o}} is for open
\begin{itemize}
\item<1-> built upon various functions in \texttt{scrbook}
\item<2-> an editable and evolving code base
\item<3-> a community of contributors
\begin{itemize}
\item<3-> \textcolor{gray}{\textit{contributing}} ideas
\item<3-> \textcolor{gray}{\textit{contributing}} problems
\item<3-> \textcolor{gray}{\textit{contributing}} solutions
\item<3-> \textcolor{gray}{\textit{contributing}} code
\end{itemize}
\item<4-> a philosophy of 'parallel publishing'
\begin{itemize}
\item<4-> \textcolor{gray}{\textit{increase}} transparency
\item<4-> \textcolor{gray}{\textit{increase}} accessibility
\end{itemize}
\end{itemize}
\begin{tikzpicture}[overlay] \node[inner sep=0pt] (one) at (10,4) {\includegraphics[height=1.2in]{scrbook.png}}; \node[inner sep=0pt] (one) at (10,0.91) {\includegraphics[height=0.8in]{oSCR.png}}; \end{tikzpicture}
$\ldots$ more about \texttt{oSCR}
\begin{itemize} \item<1-> one of several ways to analyze SCR data \begin{itemize} \item<1-> alternative (\textit{not} substitute) to \texttt{secr} \item<1-> (see Dan's lecture tomorrow) \item<1-> alternative to Bayesian analysis \end{itemize} \item<2-> likelihood based - has advantages \begin{itemize} \item<2-> \textcolor{gray}{\textit{advantage}} speed \item<2-> \textcolor{gray}{\textit{advantage}} model selection methods \item<2-> \textcolor{gray}{\textit{advantage}} cost surface modeling \item<2-> \textcolor{gray}{\textit{advantage}} user friendly \end{itemize} \end{itemize} \begin{tikzpicture}[overlay] \node[inner sep=0pt] (one) at (10,0.175) {\includegraphics[height=0.8in]{oSCR.png}}; \end{tikzpicture}
scrFrame
: the main data object for model fitting:
sf <- make.scrFrame(caphist, # spatial encounter histories traps, # trap coordinates trapCovs, # trap level covariates indCovs, # sex data trapOperation, # binary operation indicator type) # data format type
\normalsize \texttt{?make.scrFrame}
scrFrame
: the main data object for model fitting:
sf <- make.scrFrame(caphist, # spatial encounter histories traps, # trap coordinates trapCovs, # trap level covariates indCovs, # sex data trapOperation, # binary operation indicator type) # data format type
\normalsize \texttt{caphist} ($y_{ijk}$):
\scalebox{0.6}{ \begin{tikzpicture}[overlay] \matrix[draw=none,inner sep=0pt] (C) at (5,-3)[matrix of math nodes,ampersand replacement=\&,nodes={outer sep=0pt,minimum width=5mm,minimum height=5mm, anchor=center,},opacity=0.2,text height=1ex,nodes in empty cells] { 3 \& 2 \& 0 \& 0 \& \cdots \& \& \& \& \ 1 \& 0 \& 1 \& \cdots \& \& \& \& \& \ \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \vdots \ \& \& \& \& \& \& \& \vdots \& 4 \ \& \& \& \& \& \& \& 3 \& 0 \ \& \& \& \& \& \& \& 1 \& 1 \ }; \fill[gray,opacity=.2] (C-2-1.south west) -- (C-1-1.north west) -- (C-1-9.north east) -- (C-11-9.south east) -- (C-11-8.south west) -- (C-3-8.north west) -- (C-2-1.south west); \draw[opacity=0.2] (C-2-1.south west) -- (C-1-1.north west)--(C-1-9.north east)--(C-11-9.south east)--(C-11-8.south west);
\matrix[draw=none,inner sep=0pt] (D) at (4,-4)[matrix of math nodes,ampersand replacement=\&,nodes={outer sep=0pt,minimum width=5mm,minimum height=5mm, anchor=center,},opacity=0.35,text height=1ex,nodes in empty cells] { 2 \& 2 \& 1 \& 0 \& \cdots \& \& \& \& \ 4 \& 0 \& 0 \& \cdots \& \& \& \& \& \ \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \vdots \ \& \& \& \& \& \& \& \vdots \& 0 \ \& \& \& \& \& \& \& 0 \& 2 \ \& \& \& \& \& \& \& 1 \& 0 \ %%%%%% 8 }; \fill[gray,opacity=.35] (D-3-1.south west) -- (D-1-1.north west) -- (D-1-9.north east) -- (D-11-9.south east) -- (D-11-8.south west) -- (D-4-8.north west) -- (D-3-1.south west); \draw[opacity=0.35] (D-3-1.south west) -- (D-1-1.north west)--(D-1-9.north east)--(D-11-9.south east)--(D-11-8.south west);
\matrix[draw,inner sep=0pt] (E) at (3,-5) [matrix of math nodes,ampersand replacement=\&,nodes={outer sep=0pt,minimum width=5mm,minimum height=5mm, anchor=center,},opacity=1,fill=gray,text height=1ex,nodes in empty cells] { 1 \& 3 \& 0\& 1\& \cdots \& \& \& \& \ 6 \& 1 \& 2\& \& \& \& \& \& \ 0 \& 0 \& \& \& \& \& \& \& \ 3 \& \& \& \& \& \& \& \& \ \vdots \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \&\vdots \ \& \& \& \& \& \& \& \& 3 \ \& \& \& \& \& \& \& 0 \& 0 \ \& \& \& \& \& \cdots \& 0 \& 0 \& 0 \ };%
\draw[] (E-6-5) node {\large\textcolor{green}{$\boldsymbol{y_{i,j,r}}$}}; \draw[] (E-7-5) node {\large\textcolor{green}{counts}};
%Trap \draw[] (C-1-1.north east) node[above left] {\textbf{Trap = 1}}; \draw[] (C-1-9.north) node[above] {\textbf{$J$}}; \draw[->, thick] ([yshift=7.5]C-1-1.north east) -- ([yshift=7.5]C-1-9.north west);
%Ind \draw[] (E-1-1.west) node[left, yshift=2] {\textbf{Ind. = 1}}; \draw[] (E-11-1.west) node[left, yshift=2] {\textbf{$n_{obs}$}}; \draw[->, thick] ([xshift=-7.5]E-2-1.west) -- ([xshift=-7.5]E-10-1.west);
\draw[] (E-11-9.south) node[below] {\textbf{Occassion = 1}}; \draw[] (C-11-9.east) node[right, xshift=2ex] {\textbf{$K$}}; \draw[->, thick] ([xshift=2ex]E-11-9.south east) -- ([xshift=2ex]C-11-9.south east);
\matrix[draw=none,inner sep=0pt] (C) at (15,-3)[matrix of math nodes,ampersand replacement=\&,nodes={outer sep=0pt,minimum width=5mm,minimum height=5mm, anchor=center,},opacity=0.2,text height=1ex,nodes in empty cells] { 1\& 1\& 0\& 0 \& \cdots \& \& \& \& \ 1\& 0\& 1\& \cdots \& \& \& \& \& \ \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \vdots \ \& \& \& \& \& \& \& \vdots \& 1 \ \& \& \& \& \& \& \& 1 \& 0 \ \& \& \& \& \& \& \& 1 \& 1 \ %%%%%% 11 }; \fill[gray,opacity=.2] (C-2-1.south west) -- (C-1-1.north west) -- (C-1-9.north east) -- (C-11-9.south east) -- (C-11-8.south west) -- (C-3-8.north west) -- (C-2-1.south west); \draw[opacity=0.2] (C-2-1.south west) -- (C-1-1.north west)--(C-1-9.north east)--(C-11-9.south east)--(C-11-8.south west);
\matrix[draw=none,inner sep=0pt] (D) at (14,-4)[matrix of math nodes,ampersand replacement=\&,nodes={outer sep=0pt,minimum width=5mm,minimum height=5mm, anchor=center,},opacity=0.35,text height=1ex,nodes in empty cells] { 1 \& 1\& 1\& 0 \& \cdots \& \& \& \& \ 1 \& 0\& 0\& \cdots \& \& \& \& \& \ \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \vdots \ \& \& \& \& \& \& \& \vdots \& 0 \ \& \& \& \& \& \& \& 0 \& 1 \ \& \& \& \& \& \& \& 1 \& 0 \ %%%%%% 8 }; \fill[gray,opacity=.35] (D-3-1.south west) -- (D-1-1.north west) -- (D-1-9.north east) -- (D-11-9.south east) -- (D-11-8.south west) -- (D-4-8.north west) -- (D-3-1.south west); \draw[opacity=0.35] (D-3-1.south west) -- (D-1-1.north west)--(D-1-9.north east)--(D-11-9.south east)--(D-11-8.south west);
\matrix[draw,inner sep=0pt] (E) at (13,-5) [matrix of math nodes,ampersand replacement=\&,nodes={outer sep=0pt,minimum width=5mm,minimum height=5mm, anchor=center,},opacity=1,fill=gray,text height=1ex,nodes in empty cells] { 1 \& 1 \& 0 \& 1\& \cdots \& \& \& \& \ 1 \& 1 \& 1 \& \& \& \& \& \& \ 0 \& 0 \& \& \& \& \& \& \& \ 1 \& \& \& \& \& \& \& \& \ \vdots \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \ \& \& \& \& \& \& \& \& \vdots \ \& \& \& \& \& \& \& \& 1 \ \& \& \& \& \& \& \& 0 \& 0 \ \& \& \& \& \& \cdots \& 0 \& 0 \& 0 \ };%
\draw[] (E-6-5) node {\large\textcolor{green}{$\boldsymbol{y_{i,j,r}}$}}; \draw[] (E-7-5) node {\large\textcolor{green}{detections}};
%Trap \draw[] (C-1-1.north east) node[above left] {\textbf{Trap = 1}}; \draw[] (C-1-9.north) node[above] {\textbf{$J$}}; \draw[->, thick] ([yshift=7.5]C-1-1.north east) -- ([yshift=7.5]C-1-9.north west);
%Ind \draw[] (E-1-1.west) node[left, yshift=2] {\textbf{Ind. = 1}}; \draw[] (E-11-1.west) node[left, yshift=2] {\textbf{$n_{obs}$}}; \draw[->, thick] ([xshift=-7.5]E-2-1.west) -- ([xshift=-7.5]E-10-1.west);
\draw[] (E-11-9.south) node[below] {\textbf{Occassion = 1}}; \draw[] (C-11-9.east) node[right, xshift=2ex] {\textbf{$K$}}; \draw[->, thick] ([xshift=2ex]E-11-9.south east) -- ([xshift=2ex]C-11-9.south east); \end{tikzpicture} }
R
:yarr <- array(rbinom(3*10*3,1,0.4),c(3,10,3))
yarr
scrFrame
: the main data object for model fitting:
sf <- make.scrFrame(caphist, # spatial encounter histories traps, # trap coordinates trapCovs, # trap level covariates indCovs, # sex data trapOperation, # binary operation indicator type) # data format type
\normalsize \texttt{traps}:
X
and Y
(upper case)trapOperation
)scrFrame
: the main data object for model fitting:
sf <- make.scrFrame(caphist, # spatial encounter histories traps, # trap coordinates trapCovs, # trap level covariates indCovs, # sex data trapOperation, # binary operation indicator type) # data format type
\normalsize \texttt{trapCovs}:
NA
's allowedscrFrame
: the main data object for model fitting:
sf <- make.scrFrame(caphist, # spatial encounter histories traps, # trap coordinates trapCovs, # trap level covariates indCovs, # sex data trapOperation, # binary operation indicator type) # data format type
\normalsize \texttt{indCovs}:
scrFrame
: the main data object for model fitting:
sf <- make.scrFrame(caphist, # spatial encounter histories traps, # trap coordinates trapCovs, # trap level covariates indCovs, # sex data trapOperation, # binary operation indicator type) # data format type
\normalsize \texttt{trapOperation}:
scrFrame
: the main data object for model fitting:
sf <- make.scrFrame(caphist, # spatial encounter histories traps, # trap coordinates trapCovs, # trap level covariates indCovs, # sex data trapOperation, # binary operation indicator type) # data format type
\normalsize \texttt{type}:
SCR
scrFrame
: the main data object for model fitting:
make.scrFrame()
does internal checks for consistenciessf
) is ready for usescrFrame
: the main data object for model fitting:
make.scrFrame()
does internal checks for consistenciessf
) is ready for usesf <- make.scrFrame(caphist = list(ch), traps = list(tr), trapCovs = list(list(tc1,tc2,tc3)), #k=3 indCovs = list(ic), trapOperation = list(to), type = "SCR")
scrFrame
: the main data object for model fitting:
make.scrFrame()
does internal checks for consistenciessf
) is ready for usesf <- make.scrFrame(caphist = list(ch1, ch2), traps = list(tr1, tr1), trapCovs = list(list(tc1.1,tc1.2,tc1.3), list(tc2.1,tc2.2,tc2.3)), #k=3 indCovs = list(ic1, ic2), trapOperation = list(to1,to2), type = "SCR")
scrFrame
: the main data object for model fitting:
make.scrFrame()
does internal checks for consistenciessf
) is ready for usesf <- make.scrFrame(caphist = list(ch1, ch2, ch3), traps = list(tr1, tr1, tr3), trapCovs = list(list(tc1.1,tc1.2,tc1.3), list(tc2.1,tc2.2,tc2.3), list(tc3.1,tc3.2,tc3.3)), #k=3 indCovs = list(ic1, ic2, ic3), trapOperation = list(to1,to2, to3), type = "SCR")
\normalsize
$\ldots$ and so on and so forth
Data formats:
secr
format is a common formatsecr
to oSCR
formatdata2oscr()
Lets look at some real data
\begin{tikzpicture}[overlay] \node[inner sep=0pt] (one) at (9,-1) {\includegraphics[height=2.8in]{sampling.png}}; \node[inner sep=0pt] (one) at (4,-2) {\includegraphics[height=1.75in]{mark.png}}; \end{tikzpicture}
library(oSCR) data(rbs) ls() [1] "rbs.sf" "rbs.ss"
library(oSCR) data(rbs)
\normalsize
rbs.sf
is the redback salander scrFrame
objectlibrary(oSCR) data(rbs) rbs.sf
subFrame()
can be used to efficiently subset the scrFrame
sf.sub <- subFrame(scrFrame, # the scrFrame to be subsetted subs) # the index/indices to be kept
subFrame()
can be used to efficiently subset the scrFrame
sf.sub <- subFrame(scrFrame = rbs.sf, subs = c(2,4)) sf.sub
rbs
data:sf.sub <- subFrame(scrFrame = rbs.sf, subs = c(2,4)) sf.sub
State space definition is extremely important
\begin{tikzpicture}[overlay] \node[inner sep=0pt] (one) at (5,-1.5) {\includegraphics[height=1.2in]{sbuf.png}}; \end{tikzpicture}
ssDF
: the state space data object (\textbf{s}tate \textbf{s}pace {\textbf{d}ata \textbf{f}rame):
X
and Y
(upper case)traps
Making the ssDF
object requires constructing a list of data frames
ssDF <- list(ss1, # dataframe for session 1 ss2, # dataframe for session 2 ss3, # dataframe for session 3 ss4) # dataframe for session 4
Let's work with the salamander state space object:
str(rbs.ss, give.attr=FALSE)
Sub setting ssDF
is easily done:
# sub setting ssDF is easy: ss.sub <- rbs.ss[c(1,2)]
Sub setting ssDF
is easily done:
# sub setting ssDF is easy: ss.sub <- rbs.ss[c(1,2)] str(ss.sub, give.attr=FALSE)
We can plot the object
par(mfrow=c(2,2), oma=c(0,0,0,0),mar=c(4,4,2,2))
par(mfrow=c(1,4)) #4 sessions plot.ssDF(rbs.ss)
We can plot the object with the traps
par(mfrow=c(1,4)) #4 sessions plot.ssDF(rbs.ss, scrFrame=rbs.sf)
If no interest in assessing spatial variation in density
ssDF
object: make.ssDF()
ssDF <- make.ssDF(scrFrame, # an scrFRame objects buffer, # a buffer witdh (around traps!) res) # the distance between S points
par(mfrow=c(1,2))
ssDF <- make.ssDF(scrFrame = sf.sub, buffer = 1, res = 1) plot(ssDF, sf.sub)
ssDF <- make.ssDF(scrFrame = sf.sub, buffer = 5, res = 0.5) plot(ssDF, sf.sub)
With an scrFrame
and ssDF
object, we can start fitting models uning the fitting function oSCR.fit()
mod <- oSCR.fit(model, # model formulation scrFrame, # the scrFrame object ssDF, # the ssDF object encmod, # the detection function model trimS, # local evaluation distance start.vals, # parameter starting values predict, # predict desnity ...) # a few other options
mod <- oSCR.fit(model, # model formulation scrFrame, # the scrFrame object ssDF, # the ssDF object encmod, # the detection function model trimS, # local evaluation distance start.vals, # parameter starting values predict, # predict desnity ...) # a few other options
\normalsize \texttt{model}:
list(D ~ 1, p0 ~ 1, sig ~ 1, asu ~ 1)
D ~
: model describing variation in densityp0 ~
: model describing variation in baseline encounter prob/ratesig ~
: model describibg variation in sigmaasu ~
: model for a cost surfacemod <- oSCR.fit(model, # model formulation scrFrame, # the scrFrame object ssDF, # the ssDF object encmod, # the detection function model trimS, # local evaluation distance start.vals, # parameter starting values predict, # predict desnity ...) # a few other options
\normalsize \texttt{model}:
list(D ~ 1, p0 ~ 1, sig ~ 1)
D ~
: model describing variation in densityp0 ~
: model describing variation in baseline encounter prob/ratesig ~
: model describibg variation in sigmaVaraition in \textcolor{blue}{density} (D ~
)
D ~ 1 # null model, constant density D ~ session # density varies by session D ~ "covariate" # density varies by spatially indexed covariates
\normalsize
"covariate"
must match column names in ssDF
D ~ 1
is the defaultVaraition in \textcolor{blue}{detection} (p0 ~
)
p0 ~ 1 # null model, constant p (M0) p0 ~ t # occasion specific p (Mt) p0 ~ b # behavioural response (Mb) p0 ~ sex # p varies by sex p0 ~ session # p varies by session p0 ~ "covariate" # p varies by trap level covariates
\normalsize
"covariate"
must match column names in trapCovs
p0 ~ 1
is the defaultVaraition in \textcolor{blue}{sigma} (sig ~
)
sig ~ 1 # null model, constant sigma sig ~ sex # sex-specific sigma sig ~ session # session-specific sigma
\normalsize
sig ~ 1
is the defaultmod <- oSCR.fit(model, # model formulation scrFrame, # the scrFrame object ssDF, # the ssDF object encmod, # the detection function model trimS, # local evaluation distance start.vals, # parameter starting values predict, # predict desnity ...) # a few other options
\normalsize \texttt{scrFrame} and \texttt{ssDF}:
scrFame
is the encounter data objectssDF
is the state space data objectmod <- oSCR.fit(model, # model formulation scrFrame, # the scrFrame object ssDF, # the ssDF object encmod, # the detection function model trimS, # local evaluation distance start.vals, # parameter starting values predict, # predict desnity ...) # a few other options
\normalsize \texttt{encmod}:
A character defining which enccounter model to be used
"B"
: Binomial model (default)
"P"
: Poisson model
mod <- oSCR.fit(model, # model formulation scrFrame, # the scrFrame object ssDF, # the ssDF object encmod, # the detection function model trimS, # local evaluation distance start.vals, # parameter starting values predict, # predict desnity ...) # a few other options
\normalsize \texttt{trimS}:
sf1 <- subFrame(rbs.sf,1) ss1 <- rbs.ss[1] par(ask=TRUE) mod <- oSCR.fit(scrFrame=sf1, ssDF=ss1, trimS=2, plotit=TRUE) mod <- oSCR.fit(scrFrame=sf1, ssDF=ss1, trimS=4, plotit=TRUE) mod <- oSCR.fit(scrFrame=sf1, ssDF=ss1, trimS=6, plotit=TRUE) mod <- oSCR.fit(scrFrame=sf1, ssDF=ss1, trimS=NULL, plotit=TRUE) #DEFAULT
\begin{tikzpicture}[overlay] \node[inner sep=0pt] (one) at (5.5,-2) {\includegraphics[height=1.5in]{trim.png}}; \end{tikzpicture}
mod <- oSCR.fit(model, # model formulation scrFrame, # the scrFrame object ssDF, # the ssDF object encmod, # the detection function model trimS, # local evaluation distance start.vals, # parameter starting values predict, # predict desnity ...) # a few other options
\normalsize \texttt{start.vals}:
getStarts=TRUE
to get parameters and orderFor example:
sf1 <- subFrame(rbs.sf,1) ss1 <- rbs.ss[1] (oSCR.fit(model=list(D~1, p0~1, sig~1), scrFrame = sf1, ssDF = ss1, getStarts = T))
(oSCR.fit(model=list(D~1, p0~t, sig~1), scrFrame = sf1, ssDF = ss1, getStarts = T))
mod <- oSCR.fit(model, # model formulation scrFrame, # the scrFrame object ssDF, # the ssDF object encmod, # the detection function model trimS, # local evaluation distance start.vals, # parameter starting values predict, # predict desnity ...) # a few other options
\normalsize \texttt{predict}:
start.vals
Takes $\sim$ 7 mins, can get the model fits here: data(rbs.mods)
)
sf.sub <- subFrame(scrFrame = rbs.sf, subs = c(2,4)) ss.sub <- rbs.ss[c(2,4)] st <- c(-3.4, 0.04, 0.08, -1, -0.08) #NULL model (SCR0) m0 <- oSCR.fit(model=list(D~1,p0~1, sig~1), scrFrame=sf.sub, ssDF=ss.sub, trim=4, start.vals = st[c(1,3,4)])
Takes $\sim$ 7 mins, can get the model fits here: data(rbs.mods)
)
sf.sub <- subFrame(scrFrame = rbs.sf, subs = c(2,4)) ss.sub <- rbs.ss[c(2,4)] st <- c(-3.4, 0.04, 0.08, -1, -0.08) #NULL model (SCR0) m0 <- oSCR.fit(model=list(D~1,p0~1, sig~1), scrFrame=sf.sub, ssDF=ss.sub, trim=4, start.vals = st[c(1,3,4)]) #session-specific desnsity m1 <- oSCR.fit(model=list(D~session,p0~1, sig~1), scrFrame=sf.sub, ssDF=ss.sub, trim=4, start.vals = st[c(1,3,4,5)])
Takes $\sim$ 7 mins, can get the model fits here: data(rbs.mods)
)
sf.sub <- subFrame(scrFrame = rbs.sf, subs = c(2,4)) ss.sub <- rbs.ss[c(2,4)] st <- c(-3.4, 0.04, 0.08, -1, -0.08) #NULL model (SCR0) m0 <- oSCR.fit(model=list(D~1,p0~1, sig~1), scrFrame=sf.sub, ssDF=ss.sub, trim=4, start.vals = st[c(1,3,4)]) #session-specific desnsity m1 <- oSCR.fit(model=list(D~session,p0~1, sig~1), scrFrame=sf.sub, ssDF=ss.sub, trim=4, start.vals = st[c(1,3,4,5)]) #session-specific sigma m2 <- oSCR.fit(model=list(D~1,p0~1, sig~session), scrFrame=sf.sub, ssDF=ss.sub, trim=4, start.vals = st[c(1,2,3,4)])
Takes $\sim$ 7 mins, can get the model fits here: data(rbs.mods)
)
sf.sub <- subFrame(scrFrame = rbs.sf, subs = c(2,4)) ss.sub <- rbs.ss[c(2,4)] st <- c(-3.4, 0.04, 0.08, -1, -0.08) #NULL model (SCR0) m0 <- oSCR.fit(model=list(D~1,p0~1, sig~1), scrFrame=sf.sub, ssDF=ss.sub, trim=4, start.vals = st[c(1,3,4)]) #session-specific desnsity m1 <- oSCR.fit(model=list(D~session,p0~1, sig~1), scrFrame=sf.sub, ssDF=ss.sub, trim=4, start.vals = st[c(1,3,4,5)]) #session-specific sigma m2 <- oSCR.fit(model=list(D~1,p0~1, sig~session), scrFrame=sf.sub, ssDF=ss.sub, trim=4, start.vals = st[c(1,2,3,4)]) #session-specific density & sigma m3 <- oSCR.fit(model=list(D~session,p0~1, sig~session), scrFrame=sf.sub, ssDF=ss.sub, trim=4, start.vals = st[c(1,2,3,4,5)])
data(rbs.mods)
#NULL model (SCR0)
m0
#session-specific desnsity
m1
#session-specific sigma
m2
#session-specific density & sigma
m3
#session-specific density & sigma
m3
\normalsize
oSCR
has some post processing and model selection functions:
fitList.oSCR()
modSel.oSCR()
ma.coef()
oSCR
has some post processing and model selection functions:
fitList.oSCR()
oSCR
(fl <- fitList.oSCR(x, # list of fitted models rename)) # if TRUE models given sensible names
oSCR
has some post processing and model selection functions:
fitList.oSCR()
oSCR
(fl <- fitList.oSCR(list(m0,m1,m2,m3), rename=T))
oSCR
has some post processing and model selection functions:
modSel.oSCR()
fitList.oSCR
listaic.tab
)coef.tab
)ms <- modSel.oSCR(fl) ms$aic.tab
oSCR
has some post processing and model selection functions:
modSel.oSCR()
fitList.oSCR
listaic.tab
)coef.tab
)ms <- modSel.oSCR(fl) ms$coef.tab
modSel.oSCR()
ms
oSCR
has some post processing and model selection functions:
ma.coef()
modSel.oSCR
objectoSCR
has some post processing and model selection functions:
ma.coef()
modSel.oSCR
object(ma <- ma.coef(ms))
\vspace{2.5cm}
\begin{center} \Huge The \textcolor{mLightBrown}{Ocelot} data
\footnotesize photo: http://felid-tag.org/ocelot/ \end{center}
\begin{tikzpicture}[overlay] \node[inner sep=0pt] (one) at (0.5, 4.01) {\includegraphics[height=1.5in]{Ocelot_area.png}}; \node[inner sep=0pt] (one) at (10.1,-1.5) {\includegraphics[height=0.8in]{ocelot.jpg}}; \end{tikzpicture}
\small
Access the ocelot data (data(ocelot)
) and, in small groups:
Make an scrFrame
for the 2-session ocelot data
data2oscr()
, make.scrFrame()
Make a state space with a 2000m buffer and 500m resolution
make.ssDF()
, plot.ssDF()
Estimate density (/100 km^2) and sigma for the simplest SCR model
oSCR.fit()
Fit 4 models to assess variation in density and/or sigma by session
Which of theses 4 models is better supported by AIC
fitList.oSCR()
, modSel.oSCR()
, ma.coef()
scrFrame
for the 2-session ocelot datadata(ocelot) # convert 'secr' format to objects for oSCR ocelot <-data2oscr(rbind(edf1,edf2), # encounter data file K=c(44,96), # occasions per session ntraps=c(23,23), # traps per session tdf=list(tdf1,tdf2), # trap deployment files (a list) remove.zeros=TRUE, # remove uncaptured inds remove.extracaps=TRUE) # turn >1 to 1 # make the scrFrame ocelot.sf <- make.scrFrame(caphist = ocelot$y3d, traps = ocelot$traplocs, trapOperation = ocelot$trapopp, type="scr")
scrFrame
for the 2-session ocelot datapar(mfrow=c(1,2), oma=c(0,0,0,0),mar=c(1,1,1,1)) plot(ocelot.sf, ax=FALSE)
# make a state-space ocelot.ss <- make.ssDF(ocelot.sf, buffer=2000, res = 500) par(mfrow=c(1,2)) plot(ocelot.ss,ocelot.sf)
data(ocelot.mods)
# fit the null (default!) model m0 <- oSCR.fit(model=list(D ~ 1, p0 ~ 1, sig~1), # model scrFrame = ocelot.sf, # scrFrame ssDF = ocelot.ss, # ssDF trimS = 1000, se=FALSE))
m0
# NULL m0 <- oSCR.fit(model=list(D ~ 1, p0 ~ 1, sig~1), scrFrame = ocelot.sf, ssDF = ocelot.ss, trimS = 1000) # D ~ session only m1 <- oSCR.fit(model=list(D ~ session, p0 ~ 1, sig~1), scrFrame = ocelot.sf, ssDF = ocelot.ss, trimS = 1000) # sig ~ session only m2 <- oSCR.fit(model=list(D ~ 1, p0 ~ 1, sig~session), scrFrame = ocelot.sf, ssDF = ocelot.ss, trimS = 1000) # D ~ sesison AND sig ~ session m3 <- oSCR.fit(model=list(D ~ session, p0 ~ 1, sig~session), scrFrame = ocelot.sf, ssDF = ocelot.ss, trimS = 1000)
# make a 'fit list' ocelot.fl <- fitList.oSCR(list(m0,m1,m2,m3), rename = TRUE) # compare models using AIC ocelot.ms <- modSel.oSCR(ocelot.fl)
ocelot.ms$aic.tab
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.